package com.irain.pp.tool.redis.config;

import com.irain.pp.tool.redis.spring.PpRedisTemplate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;

/**
 * @author WangYanPeng
 * @date 2017/11/6 12:15
 */
@Configuration
public class RedisConfig{

    @Bean
    public PpRedisTemplate redisTemplate(RedisConnectionFactory connectionFactory){
        return new PpRedisTemplate(connectionFactory);
    }

    @Bean
    @ConfigurationProperties("spring.redis.cache")
    public RedisCacheManager cacheManager(PpRedisTemplate redisTemplate){
        RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
        cacheManager.setUsePrefix(true);
        return cacheManager;
    }
}
